﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace MvcCmsForum
{
    public class Routes : AreaRegistration
    {
        public override string AreaName
        {
            get { return "MvcCmsForum"; }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            var routes = context.Routes;

            routes.MapRoute(
                "PostAct",
                "forums-editpost/{postid}/{action}",
                new { controller = AreaName, action = "EditPost" },
                new { action = @"\w+" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "PostEditPost",
                "forums-editpost",
                new { controller = AreaName, action = "EditPost" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "PostSource",
                "forums/{postid}/source",
                new { controller = AreaName, action = "GetPostSource" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumPostCreate",
                "forums/{forumId}/post",
                new { controller = AreaName, action = "CreatePost", forumId = (int?)null },
                new { forumId = "[0-9]+" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumPostReply",
                "forums/posts/{parentPostId}/reply",
                new { controller = AreaName, action = "CreatePost", parentPostId = (int?)null },
                new { parentPostId = "[0-9]+" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumsVote",
                "forum/vote",
                new { controller = AreaName, action = "Vote" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumsFAQ",
                "forums/faq",
                new { controller = AreaName, action = "FAQ" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });


            routes.MapRoute(
                "ForumsMarkAnswer",
                "forum/markanswer",
                new { controller = AreaName, action = "MarkAnswer" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumsIndex",
                "forums",
                new { controller = AreaName, action = "Index" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumPaged",
                "forums/{path}/{page}",
                new { controller = AreaName, action = "ViewForum", path = (string)null, page = (int?)null },
                new { page = "page[0-9]+" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "Forum",
                "forums/{path}",
                new { controller = AreaName, action = "ViewForum", path = (string)null, page = 1 }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumPostPaged",
                "forums/forum-{forumpath}/{path}/page{page}",
                new { controller = AreaName, action = "ViewPost", path = (string)null, page = 1 },
                new { forumpath = "[a-zA-Z0-9\\-]+" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumPost",
                "forums/forum-{forumpath}/{path}",
                new { controller = AreaName, action = "ViewPost", path = (string)null, page = 1 },
                new { forumpath = "[a-zA-Z0-9\\-]+" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            #region Admin

            routes.MapRoute(
                "ForumCreate",
                "admin/forums/create",
                new { controller = AreaName, action = "CreateForum" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumEdit",
                "admin/forums/edit/{forumId}",
                new { controller = AreaName, action = "EditForum", forumId = (int?)null },
                new { forumId = "[0-9]+" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumRemove",
                "admin/forums/remove/{forumId}",
                new { controller = AreaName, action = "RemoveForum", forumId = (int?)null },
                new { forumId = "[0-9]+" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumPostsManager",
                "admin/forums/posts",
                new { controller = AreaName, action = "ManagePosts" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            routes.MapRoute(
                "ForumManager",
                "admin/forums",
                new { controller = AreaName, action = "ManageForums" }
            ).DataTokens = new RouteValueDictionary(new { area = AreaName });

            #endregion
        }
    }

}
